%==========================================================================
%=  This file is part of the Sound Restoration Project
%=  (c) Copyright Industrial Mathematics Institute
%=                University of South Carolina, Department of Mathematics
%=  ALL RIGHTS RESERVED
%=
%=  Author: Borislav Karaivanov
%==========================================================================

%==========================================================================
% List of the files on which this procedure depends:
%
% createMissingDirs.m
%
%==========================================================================

%==========================================================================
% The function "setGlobalVariables" sets the global variables to be used
% throughout the sound reconstruction.
% INPUT: "doVisualize" is a boolean parameter specifying whether or not to
% visualize the sound reconstruction process with figures and save
% snapshots of those figures.
% "doLog" is a boolean specifying whether or not to save to a log file with
% details and statistics about the sound reconstruction process.
% "outDirPath" is a string specifying the name (including a full directory 
% path) of a directory where the essential output files are to be written.
% "outFileNamePrefixNoPath" is a string specifying a common prefix for the
% names of the output files (NOT including directory path).
% "shotFileExt" is a string specifying the file extension to be used for
% the names of all image files saving snapshots of figures.
% OUTPUT: None.
%==========================================================================
function setGlobalVariables(doVisualize, doLog, outDirPath, outFileNamePrefixNoPath, shotFileExt)

% Define the global variables pertaining to the names of any output files
% that might be stored during execution.
global globalDoVisualize globalShotFileNamePrefix globalShotFileExt globalDoLog globalLogFileName

if (nargin < 5)
    shotFileExt = 'bmp';
end
if (nargin < 4)
    globalDoVisualize = false;
    globalShotFileNamePrefix = '';
    globalShotFileExt = '';
    globalDoLog = false;
    globalLogFileName = '';
    return;
end

% If visualization is desired, the specified output directory is a string
% representing an existing directory, and specified output file name is a
% string, then set the global variables allowing for visualization.
if ( (doVisualize == true)&&(ischar(outDirPath) == true)&&(exist(outDirPath, 'dir') == 7)&&(ischar(outFileNamePrefixNoPath) == true) )
    globalDoVisualize = true;
    globalShotFileNamePrefix = [outDirPath 'Snapshots\' outFileNamePrefixNoPath];
    globalShotFileExt = shotFileExt;
    if (strcmpi(globalShotFileExt, 'jpg') == true)
        globalShotFileExt = 'jpeg';
    end
else
    globalDoVisualize = false;
    globalShotFileNamePrefix = '';
    globalShotFileExt = '';
end

% If saving a log is desired, the specified output directory is a string
% representing an existing directory, and specified output file name is a
% string, then set the global variables allowing for visualization.
if ( (doLog == true)&&(ischar(outDirPath) == true)&&(exist(outDirPath, 'dir') == 7)&&(ischar(outFileNamePrefixNoPath) == true) )
    globalDoLog = true;
    globalLogFileName = [outDirPath 'log.txt'];
else
    globalDoLog = false;
    globalLogFileName = '';
end

% If the directory path does not exist, then create any missing directory.
createMissingDirs(globalShotFileNamePrefix);
createMissingDirs(globalLogFileName);

return;
% end of the function "setGlobalVariables"
